home *** CD-ROM | disk | FTP | other *** search
- Path: news.ov.com!news
- From: glenn@ov.com (Fletcher.Glenn@ov.com)
- Newsgroups: comp.lang.c
- Subject: Re: warning: possibly incorrect assignment
- Date: 12 Jan 1996 21:47:19 GMT
- Organization: OpenVision
- Message-ID: <4d6kt7$542@spanky.pls.ov.com>
- References: <Pine.OSF.3.91.960109091920.6447A-100000@io.UWinnipeg.ca>
- Reply-To: glenn@ov.com
- NNTP-Posting-Host: foghorn.pls.ov.com
-
- In article 100000@io.UWinnipeg.ca, Bill Simpson <wsimpson@uwinnipeg.ca> writes:
- >I get the above warning when I compile code using the following
- >function. It flags the **** line.
- >
- >void save_data(unsigned long int time[],int n)
- > {
- > char file_name[30];
- > double t;
- > int i;
- > FILE * fp;
- >
- > printf("Enter file name: ");
- > scanf("%s", file_name);
- >
- >**** while(fp=fopen(file_name,"r"))
- while((fp = fopen(file_name, "r")) != NULL)
-
- Try the above statement.
-
- > {
- > printf("this file already exists--use another name\n");
- > fclose(fp);
- > printf("Enter filename:\n");
- > scanf("%s", file_name);
- > }
- >
- > fp=fopen(file_name,"w");
- > for (i=0;i<n;i++)
- > {
- > t=(double)time[i]/1000000; /*convert from microsec to sec*/
- > fprintf(fp,"%.6f\n",t);
- > }
- > fclose(fp);
- >
- > return;
- > }
- >
- >How can I write this code so the compiler does not issue this warning?
- >Please don't suggest I just tell the compiler to shut up. In general
- >the warnings are useful. I do not want to just ignore the warning either.
- >I have the FAQ and haven't seen this discussed.
- >
- >(Any other improvements to above code segment welcomed)
- >
- >Thanks very much for any help.
- >
- >Bill Simpson
-
-
-
- Basically the compiler is complaining that there is an assignment
- in a conditional context, thinking you might mean ==. If you
- encapsulate the assignment and then make a comparison, you are
- demonstrating that you really mean = and not ==.
-
- Fletcher.Glenn@ov.com
-
-